﻿using System;
using System.Collections.Generic;

namespace CARMSBusiness
{
   public static class StringExtender
    {
       public static List<string> SeperateString(this string strInput, char strSeperateChar)
       {
           var listReturn = new List<string>();
           if (strInput.IndexOf(strSeperateChar) > 0)
           {
               string[] split = strInput.Split(strSeperateChar);
               foreach (var s in split)
               {
                   if (s.Trim().Length > 0)
                   {
                       listReturn.Add(s);
                   }
               }
           }
           else
           {
               if (strInput.Trim().Length > 0)
               {
                   listReturn.Add(strInput);
               }
           }

           return listReturn;
       }

       public static List<Guid> SeperateStringToGuid(this string strInput, char strSeperateChar)
       {
           var listReturn = new List<Guid>();
           if (strInput.IndexOf(strSeperateChar) > 0)
           {
               string[] split = strInput.Split(strSeperateChar);
               foreach (var s in split)
               {
                   if (s.Trim().Length > 0)
                   {
                       listReturn.Add(new Guid(s));
                   }
               }
           }
           else
           {
               if (strInput.Trim().Length > 0)
               {
                   listReturn.Add(new Guid(strInput));
               }
           }

           return listReturn;
       }

       /// <summary>
       /// 取前n个字段，不足时补 emptyWord
       /// </summary>
       /// <param name="strInput"></param>
       /// <param name="length"></param>
       /// <returns></returns>
       public static string SubFixLengthString(this string strInput,int length,char emptyChar)
       {
           if (strInput.Length <= length)
           {
               var strEmp = string.Empty;
               for (int i = 0; i < length - strInput.Length;i++ )
               {
                   strEmp += emptyChar;
               }

               return strInput + strEmp;
           }
           else
           {  
               return strInput.Substring(0, length);
           }
       }
    }
}
